package chain_token

import (
	"chain_bridge_service/configs"
	"context"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo"
)

type ChainToken struct {
	Id            string `bson:"_id,omitempty" json:"id"`
	Address       string `bson:"address" json:"address"`
	Name          string `bson:"name" json:"name"`
	Symbol        string `bson:"symbol" json:"symbol"`
	Decimals      uint   `bson:"decimals" json:"decimals"`
	ChainConfigId string `bson:"chainConfigId" json:"chainConfigId"`
}

func GetInfoById(client *mongo.Client, id string) (ChainToken, error) {
	var token ChainToken
	cfg := configs.Get().Mongodb
	tokenClient := client.Database(cfg.Config.Name).Collection("chain_token")
	objId, _ := primitive.ObjectIDFromHex(id)
	err := tokenClient.FindOne(context.TODO(), bson.M{"_id": objId}).Decode(&token)
	return token, err
}
